﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using ProjectVLIB.DAL;

namespace ProjectVLIB
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                //string ma 
                DataAccess da = new DataAccess();
                dataGridView1.DataSource = da.GetDataLoaiHang();
                label1.Text = da.GetCountLoaiHang().ToString();
            }
            catch
            {
                label1.Text = "Ket noi that bai";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // t
            string tenLoaiHang = textBox1.Text;
            DataAccess da = new DataAccess();
            da.InsertLoaiHang(tenLoaiHang);

            // load lai du lieu
            dataGridView1.DataSource = da.GetDataLoaiHang();
            label1.Text = da.GetCountLoaiHang().ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DataAccess da = new DataAccess();
            string ma = textBox2.Text;
            dataGridView1.DataSource = da.GetDataLoaiHang(ma);

        }
    }
}
